package com.example.skudemo.controller;


import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.skudemo.enums.StatusEnum;
import com.example.skudemo.model.AttributeValueEntity;
import com.example.skudemo.service.IAttributeValueService;
import com.example.skudemo.utils.ApiResult;
import com.example.skudemo.vo.AttributeValueListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 商品属性值表 前端控制器
 * </p>
 *
 * @author 水痕
 * @since 2023-11-17
 */
@RestController
@RequestMapping("/attributeValue")
public class AttributeValueController {
    @Autowired
    private IAttributeValueService propertyValueService;

    @GetMapping("{attributeId}")
    public ApiResult getPropertyValueByPropertyIdApi(@PathVariable Integer attributeId) {
        LambdaQueryWrapper<AttributeValueEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.
                eq(AttributeValueEntity::getAttributeId,attributeId).
                eq(AttributeValueEntity::getStatus, StatusEnum.NORMAL.getCode());
        List<AttributeValueEntity> attributeValueEntityList = this.propertyValueService.list(queryWrapper);
        List<AttributeValueListVO> attributeValueListVOS = BeanUtil.copyToList(attributeValueEntityList, AttributeValueListVO.class);
        return ApiResult.success(attributeValueListVOS);
    }
}
